package shanghaielectric.com.shanghaielectric.Communication;

import android.os.Build;
import android.support.annotation.RequiresApi;

import java.util.HashMap;
import java.util.Map;

import shanghaielectric.com.shanghaielectric.DeviceConfigModel.Device.Device;
import shanghaielectric.com.shanghaielectric.DeviceConfigModel.Device.DeviceModbusRTU;
import shanghaielectric.com.shanghaielectric.DeviceConfigModel.Point.ProtocolParam_Point_Modbus;
import shanghaielectric.com.shanghaielectric.EnumDataHelper;
import shanghaielectric.com.shanghaielectric.MyApplication;
import shanghaielectric.com.shanghaielectric.RDBHelper.Cell_show;
import shanghaielectric.com.shanghaielectric.RDBHelper.RDBHelper;
import shanghaielectric.com.shanghaielectric.Utils.ByteUtils;

/**
 * Created by 45000460 on 2017/11/7.
 */

public class CommHelper {
    public Map<Integer, Device> deviceMap;

    public CommHelper() {
        deviceMap = MyApplication.myApplication.getDevices();
    }

//    public void setCommunicateData() {
//        RDBHelper.getInstance().putPointValue_commValue(deviceTypeID, pointID, CommunicateValue);
//        RDBHelper.getInstance().putPointValue_writeValue(deviceTypeID, pointID, PutWriteValue);
//        RDBHelper.getInstance().getCellsCollection_show();//获得对外显示的数据
//        RDBHelper.getInstance().getCellsCollection();//获得内部实时数据
//    }


    public void sendRequest(int deviceID) {
        Device device = deviceMap.get(deviceID);

        if (EnumDataHelper.PROTOCOL_TYPE.RTU.equals(device.protocolType)){


        }

    }



    /**
     * modbus 协议----对设备写数据
     */
    @RequiresApi(api = Build.VERSION_CODES.N)
    public void writeCommuntcateData_Modbus(int deviceID, int pointID, String value) {
        RDBHelper.getInstance().putPointValue_writeValue(deviceID, pointID, value);
    }


    /**
     * 104 协议
     */
    public void receiveCommuntcateData_104(int deviceID, byte[] receiveDatas) {

    }


    //对外提供显示数据
    public Map<Integer, Map<Integer, Cell_show>> getCommuntcateData() {

        return RDBHelper.getInstance().getCellsCollection_show();
    }


}

